﻿/*
 * Copyright (c) Seagull Consulting, Inc. All rights reserved. See License.txt in the project root for license information.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SeagullConsulting.MvcAjaxControls.Data.Models;

namespace SeagullConsulting.MvcAjaxControls.Data.Repository
{
    public class PhoneRepository
    {
        IList<Phone> phones;

        public PhoneRepository()
        {
            phones = new List<Phone>() { 
                new Phone() { Id = 1, Number = "(813) 258-9423", PersonId = 1 },
                new Phone() { Id = 2, Number = "(813) 317-8254", PersonId = 1 },
                new Phone() { Id = 3, Number = "(813) 555-1234", PersonId = 2 },
                new Phone() { Id = 4, Number = "(813) 555-1212", PersonId = 2 }
            };
        }

        public IQueryable<Phone> List()
        {
            return phones.OrderBy(p => p.Number).AsQueryable();
        }

        public IQueryable<Phone> List(int personId)
        {
            return phones.Where(p => p.PersonId == personId).OrderBy(c => c.Number).AsQueryable();
        }

        public IQueryable<Phone> List(PagerParms pagerParms)
        {

            return phones.OrderBy(c => c.Number)
                    .Skip((pagerParms.PageNbr) * pagerParms.PageSize)
                    .Take(pagerParms.PageSize)
                    .AsQueryable();
        }

        public IQueryable<Phone> List(int personId, PagerParms pagerParms)
        {

            return phones.OrderBy(c => c.Number)
                    .Skip((pagerParms.PageNbr) * pagerParms.PageSize)
                    .Take(pagerParms.PageSize)
                    .Where(p => p.PersonId == personId)
                    .AsQueryable();
        }

        public int ListCount()
        {
            return phones.Count();
        }


        public int ListCount(int personId)
        {
            return phones.Where(p => p.PersonId == personId).Count();
        }

    }
}